package pwd.allen.androiddemo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import pwd.allen.androiddemo.R;

public class SelectFragment extends Fragment {

    private static final String TAG = "fragment";

    public static SelectFragment newInstance(String desc) {
        SelectFragment fragment = new SelectFragment();
        // 把参数打包，传入fragment中
        Bundle args = new Bundle();
        args.putString("desc", desc);
        fragment.setArguments(args);
        return fragment;
    }

    // 创建碎片视图
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // 根据布局文件fragment_dynamic.xml生成视图对象
        View view = inflater.inflate(R.layout.item_select, container, false);
        String desc = "默认值";
        Bundle arguments = getArguments();
        if (arguments != null){
            desc = arguments.getString("desc", "默认值");
        }
        TextView tv_desc = view.findViewById(R.id.tv_desc);
        tv_desc.setText(desc);
        return view;
    }

}